<?php
	
	//获取博文列表数据
	if(isset($_GET['page'])){
		$page = $_GET['page'];
	}else{
		$page = 1;
	}
	if(isset($_GET['type'])){
		$article = getArticleList(($page-1)*5,(int)getConfig('listnum'),$_GET['type']);
		$num = getArticleNum($_GET['type']);
		$pagenum = (int)(($num-1)/(int)getConfig('listnum'))+1;
		$smarty->assign('type',$_GET['type']+1);
	}else{
		if($page==1){
			$toparticle = getTopArticle();
		}
		$article = getArticleList(($page-1)*5,(int)getConfig('indexnum'));
		$num = getArticleNum();
		$pagenum = (int)(($num-1)/(int)getConfig('indexnum'))+1;
	}
	$smarty->assign('article',$article);
	if(isset($toparticle)){
		$smarty->assign('toparticle',$toparticle);
	}
	//获取边栏数据
	$smarty->assign('artnum',getArticleNum());
	$smarty->assign('remarknum',getRemarkNum());
	//分页
	$pagearr = array();
	if(isset($_GET['page'])){
		$smarty->assign('nowpage',$_GET['page']);
		if($_GET['page']-4>1){
			for($i=$_GET['page']-4;$i<$_GET['page'];$i++){
				array_push($pagearr, $i);
			}
			for($i=$_GET['page'];$i<=$_GET['page']+4;$i++){
				if($i>$pagenum){
					break;
				}
				array_push($pagearr, $i);
			}
		}else{
			for($i=1;$i<=10;$i++){
				if($i>$pagenum){
					break;
				}
				array_push($pagearr, $i);				
			}
		}
	}else{
		$smarty->assign('nowpage',1);
		for($i=1;$i<=10;$i++){
			if($i>$pagenum){
				break;
			}
			array_push($pagearr, $i);				
		}
	}
	$smarty->assign('pagearr',$pagearr);
	$smarty->assign('pagenum',$pagenum);
	//获取最新评论数据
	$tempRemark = getRemarkList(5);
	$remark = array();
	foreach($tempRemark as $value){
		$temp = array();
		$temp['time'] = turnTimeToDate($value['pubtime']);
		$temp['content'] = $value['content'];
		if($value['authorid'] == 0){
			$temp['name'] = $value['name'];
			$temp['headpic'] = 'none.png';
		}else{
			$user = getUserById($value['authorid']);
			$temp['name'] = $user['username'];
			$temp['headpic'] = $user['headpic'];
		}
		array_push($remark, $temp);
	}
	$smarty->assign('remark',$remark);

	//站点标题
	$sitetitle = getConfig('title');
	if(getConfig('addtitle')!=''){
		$sitetitle.=' - '.getConfig('addtitle');
	}
	$sitetitle.=' - Powered by MoodBlog';
	$smarty->assign('sitetitle',$sitetitle);

	$smarty->display($_config['root']."templete/{$style}/index.html");
?>